﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace XMouse360
{
	public static class InputData
	{
		public static VK StringToVK(string input)
		{

			return (VK)Enum.Parse(typeof(VK), input);
		}

		public static string VKToString(VK input)
		{
			return Enum.GetName(typeof(VK), input);
		}

		public enum VK : ushort
		{
			SHIFT = 0x10,
			CONTROL = 0x11,
			MENU = 0x12,
			ESCAPE = 0x1B,
			BACK = 0x08,
			TAB = 0x09,
			RETURN = 0x0D,
			PRIOR = 0x21,
			NEXT = 0x22,
			END = 0x23,
			HOME = 0x24,
			LEFT = 0x25,
			UP = 0x26,
			RIGHT = 0x27,
			DOWN = 0x28,
			SELECT = 0x29,
			PRINT = 0x2A,
			EXECUTE = 0x2B,
			SNAPSHOT = 0x2C,
			INSERT = 0x2D,
			DELETE = 0x2E,
			HELP = 0x2F,
			NUMPAD0 = 0x60,
			NUMPAD1 = 0x61,
			NUMPAD2 = 0x62,
			NUMPAD3 = 0x63,
			NUMPAD4 = 0x64,
			NUMPAD5 = 0x65,
			NUMPAD6 = 0x66,
			NUMPAD7 = 0x67,
			NUMPAD8 = 0x68,
			NUMPAD9 = 0x69,
			MULTIPLY = 0x6A,
			ADD = 0x6B,
			SEPARATOR = 0x6C,
			SUBTRACT = 0x6D,
			DECIMAL = 0x6E,
			DIVIDE = 0x6F,
			F1 = 0x70,
			F2 = 0x71,
			F3 = 0x72,
			F4 = 0x73,
			F5 = 0x74,
			F6 = 0x75,
			F7 = 0x76,
			F8 = 0x77,
			F9 = 0x78,
			F10 = 0x79,
			F11 = 0x7A,
			F12 = 0x7B,
			OEM_1 = 0xBA,   // ',:' for US
			OEM_PLUS = 0xBB,   // '+' any country
			OEM_COMMA = 0xBC,   // ',' any country
			OEM_MINUS = 0xBD,   // '-' any country
			OEM_PERIOD = 0xBE,   // '.' any country
			OEM_2 = 0xBF,   // '/?' for US
			OEM_3 = 0xC0,   // '`~' for US
			MEDIA_NEXT_TRACK = 0xB0,
			MEDIA_PREV_TRACK = 0xB1,
			MEDIA_STOP = 0xB2,
			MEDIA_PLAY_PAUSE = 0xB3,
			LWIN = 0x5B,
			RWIN = 0x5C,
			BROWSER_BACK = 0xA6,
			BROWSER_FORWARD = 0xA7,
			BROWSER_REFRESH = 0xA8,
			BROWSER_SEARCH = 0xAA,
			BROWSER_FAVORITES = 0xAB,
			BROWSER_HOME = 0xAC,
			VOLUME_MUTE = 0xAD,
			VOLUME_DOWN = 0xAE,
			VOLUME_UP = 0xAF,
			LAUNCH_MAIL = 0xB4,
			SLEEP = 0x5F,
			NUMLOCK = 0x90,
			SCROLL = 0x91,
			LSHIFT = 0xA0,
			RSHIFT = 0xA1,
			LCONTROL = 0xA2,
			RCONTROL = 0xA3
		}

		public static int MouseInputSize
		{
			get { return 28; }
		}

		[StructLayout(LayoutKind.Sequential)]
		public struct MOUSEINPUT
		{
			public int dx;
			public int dy;
			public int mouseData;
			public uint dwFlags;
			public uint time;
			public uint dwExtraInfo;
		}

		public static int KebdInputSize
		{
			get { return 2 + 2 + 4 + 4 + 4 + 4; }
		}
				

		[StructLayout(LayoutKind.Sequential)]
		public struct KEYBDINPUT : System.Collections.IEnumerable
		{
			
			public ushort wVk;
			public ushort wScan;
			public uint dwFlags;
			public uint time;
			public uint dwExtraInfo;

			public System.Collections.IEnumerator GetEnumerator()
			{
				return (System.Collections.IEnumerator)new List<int>();
			}
		}

		[StructLayout(LayoutKind.Sequential)]
		public struct HARDWAREINPUT
		{
			public uint uMsg;
			public ushort wParamL;
			public ushort wParamH;
		}

		[StructLayout(LayoutKind.Explicit)]
		public struct INPUT
		{
			[FieldOffset(0)]
			public int type;
			[FieldOffset(4)]
			public MOUSEINPUT mi;
			[FieldOffset(4)]
			public KEYBDINPUT ki;
			[FieldOffset(4)]
			public HARDWAREINPUT hi;
		}

		//[DllImport("user32.dll", SetLastError = true)]
		//private static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);

		public static string InputTypeToString(INPUTTYPE input)
		{
			return Enum.GetName(typeof(INPUTTYPE), input);
		}

		public static INPUTTYPE StringToInputType(string input)
		{
			return (INPUTTYPE)Enum.Parse(typeof(INPUTTYPE), input);
		}


		public enum INPUTTYPE : int
		{
			INPUT_MOUSE = 0,
			INPUT_KEYBOARD = 1,
			INPUT_HARDWARE = 2,
			INPUT_OTHER = 3

		}

		public const int INPUT_MOUSE = 0;
		public const int INPUT_KEYBOARD = 1;
		public const int INPUT_HARDWARE = 2;
		public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
		public const uint KEYEVENTF_KEYUP = 0x0002;
		public const uint KEYEVENTF_UNICODE = 0x0004;
		public const uint KEYEVENTF_SCANCODE = 0x0008;
		public const uint XBUTTON1 = 0x0001;
		public const uint XBUTTON2 = 0x0002;

		public static MOUSEEVENT StringToMouseEvent(string input)
		{
			return (MOUSEEVENT)Enum.Parse(typeof(MOUSEEVENT), input);
		}

		public static string MouseEventToString(MOUSEEVENT input)
		{
			return Enum.GetName(typeof(MOUSEEVENT), input);
		}

		public enum MOUSEEVENT : uint
		{
			MOUSEEVENTF_MOVE = 0x0001,
			MOUSEEVENTF_LEFTDOWN = 0x0002,
			MOUSEEVENTF_LEFTUP = 0x0004,
			MOUSEEVENTF_RIGHTDOWN = 0x0008,
			MOUSEEVENTF_RIGHTUP = 0x0010,
			MOUSEEVENTF_MIDDLEDOWN = 0x0020,
			MOUSEEVENTF_MIDDLEUP = 0x0040,
			MOUSEEVENTF_XDOWN = 0x0080,
			MOUSEEVENTF_XUP = 0x0100,
			MOUSEEVENTF_WHEEL = 0x0800,
			MOUSEEVENTF_VIRTUALDESK = 0x4000,
			MOUSEEVENTF_HWHEEL = 0x1000,
			MOUSEEVENTF_ABSOLUTE = 0x8000
		}
	}
}
